package com.ixoko.swagger.dto;


import com.ixoko.swagger.constant.GlobalConstant;
import com.ixoko.swagger.enums.ErrorCode;
import com.ixoko.swagger.resp.GetClientGuiderBasicRespDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 消息体
 *
 * @param <T>
 * @author wuxj
 */
public class BaseResDto<T> {

    @ApiModelProperty(value = "调用结果标志位 false:失败 true:成功")
    protected boolean flag = GlobalConstant.REQUEST_RESULT_SUCCESSED;//

    @ApiModelProperty(value = "错误编码")
    protected String errorCode = ErrorCode.S000000.getCode();//

    @ApiModelProperty(value = "错误信息")
    protected String errorMsg = ErrorCode.S000000.getDesc();//

    @ApiModelProperty(value = "分页数据的总数")
    protected int pageCount = 0;//

    @ApiModelProperty(value = "data")
    protected T data;//返回的内容

    public boolean isFlag() {
        if (!ErrorCode.S000000.getCode().equals(errorCode)) {
            flag = false;
        }
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public void setError(String errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        isFlag();
    }

    public void setError(ErrorCode ErrorCode) {
        this.errorCode = ErrorCode.getCode();
        this.errorMsg = ErrorCode.getDesc();
        isFlag();
    }

    public String getErrorCode() {
        return errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }
}
